local H = require "packages/hegemony/util"
local HM = require "packages/mod_hegemony/util"
local U = require "packages/utility/utility"
local extension = Package:new("heg_ofl")
extension.extensionName = "mod_hegemony"
extension.game_modes_whitelist = { 'nos_heg_mode', 'new_heg_mode' }
extension:loadSkillSkelsByPath("./packages/mod_hegemony/pkg/heg_ofl/skills")

Fk:loadTranslationTable{
  ["heg_ofl"] = "国战-线下补充",
  ["ofl_heg"] = "线下补充",
}

local wangji = General(extension, "ofl_heg__wangji", "wei", 3)
wangji:addSkill("qizhi")
wangji:addSkill("jinqu")
Fk:loadTranslationTable{
  ["ofl_heg__wangji"] = "王基",
  ["#ofl_heg__wangji"] = "经行合一",
  ["illustrator:ofl_heg__wangji"] = "雪君S",
  ["designer:ofl_heg__wangji"] = "韩旭",
  ["ofl__qizhi"] = "奇制",
  [":ofl__qizhi"] = "当你于回合内使用非装备牌指定目标后，你可以弃置一名不为目标的角色的一张牌，然后令其摸一张牌。",
  ["@ofl__qizhi-turn"] = "奇制",
  ["#ofl__qizhi-choose"] = "奇制：你可以弃置一名角色一张牌，然后其摸一张牌",

  ["$ofl__qizhi1"] = "声东击西，敌寇一网成擒。",
  ["$ofl__qizhi2"] = "吾意不在此地，已遣别部出发。",
  ["~ofl_heg__wangji"] = "天下之势，必归大魏，可恨，未能得见呐！",
}

local guohuai = General(extension, "ofl_heg__guohuai", "wei", 4)
guohuai.mainMaxHpAdjustedValue = -1
guohuai:addSkill("ofl__duanshi")
guohuai:addSkill("ofl__jingce")
Fk:loadTranslationTable{
  ["ofl_heg__guohuai"] = "郭淮",
  ["#ofl_heg__guohuai"] = "垂问素雍",
  ["illustrator:ofl_heg__guohuai"] = "心中一凛",
  ["ofl__duanshi"] = "断势",
  [":ofl__duanshi"] = "主将技，锁定技，此武将减少一个单独阴阳鱼。其他角色因杀死与你势力相同的其他角色而执行奖惩摸牌时，你令其少摸一张牌，然后你摸一张牌",
  ["ofl__jingce"] = "精策",
  [":ofl__jingce"] = "回合结束时，若本回合内置入弃牌堆的牌数不小于X，你可以执行一个额外的摸牌阶段；若本回合你使用过的牌数不小于X，你可以执行一个额外的出牌阶段（X为你的体力值）。",
  ["#ofl__jingce-draw"] = "精策：你可以执行一个额外的摸牌阶段",
  ["#ofl__jingce-play"] = "精策：你可以执行一个额外的出牌阶段",

  ["$ofl__jingce1"] = "精细入微，策敌制胜。",
  ["$ofl__jingce2"] = "妙策如神，精兵强将，安有不胜之理？",
  ["~ofl_heg__guohuai"] = "岂料姜维……空手接箭！",
}


local guanqiujian = General(extension, "ofl_heg__guanqiujian", "wei", 4)
guanqiujian:addSkill("ofl__zhengrong")
guanqiujian:addSkill("ofl__hongju")
guanqiujian:addCompanions("ld__wenqin")
Fk:loadTranslationTable{
  ["ofl_heg__guanqiujian"] = "毌丘俭",
  ["#ofl_heg__guanqiujian"] = "攻破东川",
  ["ofl_heg__zhengrong"]  = "征荣",
  [":ofl_heg__zhengrong"] = "锁定技，当你造成或受到伤害时，若场上没有与受伤角色或伤害来源势力相同的其他角色，此伤害+1。",
  ["ofl_heg__hongju"] = "鸿举",
  [":ofl_heg__hongju"] = "限定技，出牌阶段，你可以选择一名其他角色，然后令其以外的角色依次执行一次“军令”（你额外抽取两张军令且你必须执行），不执行的角色本回合移出游戏。", 

  ["$ofl_heg__zhengrong1"] = "此役兵戈所向，贼众望风披靡。",
  ["$ofl_heg__zhengrong2"] = "世袭兵道，唯愿一扫蛮夷。",
  ["$ofl_heg__hongju1"] = "鸿飞冲云天，魂归入魏土。",
  ["$ofl_heg__hongju2"] = "吾负淮阴之才，岂能受你摆布！",
  ["~ofl_heg__guanqiujian"] = "好谋而不达，此事必有隐患。",
}
--[[
local wangling = General(extension, "ofl_heg__wangling", "wei", 4)
local mibei = fk.CreateViewAsSkill{
  name = "ofl_heg__mibei",
  anim_type = "special",
  pattern = ".",
  prompt = "#ofl_heg__mibei-prompt",
  interaction = function(self)
    local cids = table.filter(Self:getCardIds("h"), function(id)
      return Fk:getCardById(id):getMark("@@mibei_cardMark-inhand") ~= 0 and (Fk:getCardById(id):isCommonTrick() or Fk:getCardById(id).type == Card.TypeBasic)
    end)
    local cards  = table.map(cids, function(id)
      return Fk:getCardById(id).name 
    end)
    return UI.ComboBox {
      choices = cards
    }
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select):getMark("@@mibei_cardMark-inhand") ~= 0
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return end
    local card = Fk:cloneCard(self.interaction.data)
    card:addSubcard(cards[1])
    card.skillName = self.name
    return card
  end,
  enabled_at_play = function(self, player)
    return table.find(player:getCardIds("h"), function(id)
      return Fk:getCardById(id):getMark("@@mibei_cardMark-inhand") ~= 0
    end) and player:usedSkillTimes(self.name) == 0
  end,
  enabled_at_response = function(self, player, response)
    return not response and table.find(player:getCardIds("h"), function(id)
      return Fk:getCardById(id):getMark("@@mibei_cardMark-inhand") ~= 0
    end) and player:usedSkillTimes(self.name) == 0
  end,
}

local mibei_trigger = fk.CreateTriggerSkill{
  name = "#ofl_heg__mibei_trigger",
  anim_type = "special",
  events = {fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and not table.every(player.room:getOtherPlayers(player), function(p)
      return #player:getCardIds("h") >= #p:getCardIds("h")
    end)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room.alive_players, function(p1)
      return table.every(player.room:getOtherPlayers(player), function(p2)
        return #p1:getCardIds("h") >= #p2:getCardIds("h")
      end)
    end)
    targets = table.map(targets, Util.IdMapper)
    local to = room:askForChoosePlayers(player, targets, 1, 1, "#ofl_heg__mibei-invoke", self.name, true)
    if #to > 0 then
      self.cost_data = to
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data[1])
    player:broadcastSkillInvoke("ofl_heg__mibei", table.random({1, 2}))
    local isDoCommand = H.askCommandTo(to, player, self.name)
    if isDoCommand then
      local num = math.min(5, #to:getCardIds("h") - #player:getCardIds("h"))
      if num > 0 then
        player:drawCards(num, self.name)
      end
    else
      local cards = room:askForCard(player, 1, 3, false, self.name, true, ".", "#ofl_heg__mibei-choose")
      if #cards > 0 then
        player:showCards(cards)
        for _, id in ipairs(cards) do
          local c = Fk:getCardById(id)
          room:setCardMark(c, "@@mibei_cardMark-inhand", 1)
        end
      end
    end
  end,
}
mibei:addRelatedSkill(mibei_trigger)
wangling:addSkill(mibei)
Fk:loadTranslationTable{
  ["ofl_heg__wangling"] = "王凌",
  ["#ofl_heg__wangling"] = "深谋远虑",
  ["ofl_heg__mibei"] = "秘备",
  [":ofl_heg__mibei"] = "回合开始时，若你的手牌数不为场上最多，你选择场上手牌数最多的一名角色，该角色令你执行一次“军令”；若你执行，你将手牌摸至X(X为军令发起者的手牌数，至多摸5张)；若你不执行，你可以展示一至三张手牌直到本回合结束，"..
  "每回合限一次，你可将“秘备”展示的牌当其中一张基本牌或普通锦囊牌使用。",
  ["#ofl_heg__mibei_trigger"] = "秘备",
  ["#ofl_heg__mibei-invoke"] = "秘备：你可以选择一名角色，发动“秘备”",
  ["@@mibei_cardMark-inhand"] = "秘备",
  ["#ofl_heg__mibei-prompt"] = "秘备：你可以将一张“秘备”牌当其中一张牌使用",
  ["#ofl_heg__mibei-choose"] = "秘备：你可以选则一名角色，然后其令你执行军令",

  ["$ofl_heg__mibei4"] = "先谋后事者昌，先事后谋者亡！",
  ["$ofl_heg__mibei3"] = "司马氏虽权尊势重，吾等徐图亦无不可！",
  ["$ofl_heg__mibei1"] = "密为之备，不可有失。",
  ["$ofl_heg__mibei2"] = "事以密成，语以泄败！",
  ["~ofl_heg__wangling"] = "一生尽忠事魏，不料今日晚节尽毁啊！",
}

local huangquan = General(extension, "ofl_heg__huangquan", "shu", 3)
huangquan.subkingdom = "wei"
local dianhu = fk.CreateTriggerSkill{
  name = "ofl_heg__dianhu",
  events = {fk.GeneralRevealed},
  frequency = Skill.Compulsory,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if event == fk.GeneralRevealed and player:usedSkillTimes(self.name, Player.HistoryGame) == 0 and player:hasSkill(self, true) then
      for _, v in pairs(data) do
        if v == "ofl_heg__huangquan" then return true end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:notifySkillInvoked(player, self.name)
    player:broadcastSkillInvoke(self.name, 1)
    local targets = table.map(room:getOtherPlayers(player), Util.IdMapper)
    local tos = room:askForChoosePlayers(player, targets, 1, 1, "#ofl_heg__dianhu-choose", self.name, false)
    if #tos == 0 then
      tos = table.random(targets, 1)
    end
    local to = room:getPlayerById(tos[1])
    local mark =  to:getTableMark("@@ofl_heg__dianhu")
    table.insert(mark, player.id)
    room:setPlayerMark(to, "@@ofl_heg__dianhu", mark)
  end,

  refresh_events = {fk.BuryVictim},
  can_refresh = function(self, event, target, player, data)
    return not player.dead and type(player:getMark("@@ofl_heg__dianhu")) == "table"
  end,
  on_refresh = function(self, event, target, player, data)
    local mark = player:getMark("@@ofl_heg__dianhu")
    table.removeOne(mark, target.id)
    player.room:setPlayerMark(player, "@@ofl_heg__dianhu", #mark > 0 and mark or 0)
  end,
}
local dianhu_delay = fk.CreateTriggerSkill{
  name = "#ofl_heg__dianhu_delay",
  events = {fk.Damaged},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if target and not (player.dead or target.dead) then
      local mark =  target:getTableMark("@@ofl_heg__dianhu")
      if table.contains(mark, player.id) then
        if event == fk.Damaged then
          return H.compareKingdomWith(data.from, player)
        end
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local from = data.from
    player:broadcastSkillInvoke(dianhu.name, 2)
    from:drawCards(1, dianhu.name)
  end,
}
local jianji = fk.CreateActiveSkill{
  name = "ofl_heg__jianji",
  anim_type = "support",
  card_num = 0,
  target_num = 1,
  prompt = "#ofl_heg__jianji-prompt",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected)
    return #selected == 0 and to_select ~= Self.id
  end,
  on_use = function(self, room, effect)
    local target = room:getPlayerById(effect.tos[1])
    local id = target:drawCards(1, self.name)[1]
    target:showCards(id)
    if not target.dead and table.contains(target.player_cards[Player.Hand], id) then
      U.askForUseRealCard(room, target, {id}, ".", self.name)
    end
  end,
}
dianhu:addRelatedSkill(dianhu_delay)
huangquan:addSkill(dianhu)
huangquan:addSkill(jianji)
Fk:loadTranslationTable{
  ["ofl_heg__huangquan"] = "黄权",
  ["#ofl_heg__huangquan"] = "道绝殊途",
  ["illustrator:ofl_heg__huangquan"] = "匠人绘",

  ["ofl_heg__dianhu"] = "点虎",
  [":ofl_heg__dianhu"] = "锁定技，当你首次明置此武将时，你指定一名其他角色；当与你势力相同的角色对该角色造成伤害后，其摸一张牌。",
  ["ofl_heg__jianji"] = "谏计",
  [":ofl_heg__jianji"] = "出牌阶段限一次，你可以令一名其他角色摸一张牌并展示之，然后其可以使用该牌。",
  ["#ofl_heg__dianhu_delay"] = "点虎",
  ["@@ofl_heg__dianhu"] = "点虎",
  ["#ofl_heg__dianhu-choose"] = "点虎：指定一名角色，本局当你对其造成伤害或其回复体力后，你摸一张牌",
  ["#ofl_heg__jianji-invoke"] = "谏计：你可以使用这张牌",
  ["#ofl_heg__jianji-prompt"] = "谏计：你可令一名其他角色摸一张牌，且其可以使用之",

  ["$ofl_heg__dianhu1"] = "预则立，不预则废！",
  ["$ofl_heg__dianhu2"] = "就用你，给我军祭旗！",
  ["$ofl_heg__jianji1"] = "锦上添花，不如雪中送炭。",
  ["$ofl_heg__jianji2"] = "密计交于将军，可解燃眉之困。",
  ["~ofl_heg__huangquan"] = "魏王厚待于我，降魏又有何错？",
}


local yanyan = General(extension, "ofl_heg__yanyan", "shu", 4)
local juzhan = fk.CreateTriggerSkill{
  name = "ofl__juzhan",
  switch_skill_name = "ofl__juzhan",
  anim_type = "switch",
  events = { fk.TargetSpecified, fk.TargetConfirmed },
  can_trigger = function(self, event, target, player, data)
    if not (target == player and player:hasSkill(self) and
      data.card.trueName == 'slash') then return end

    local isYang = player:getSwitchSkillState(self.name) == fk.SwitchYang
    if event == fk.TargetConfirmed and isYang then
      return player.id ~= data.from
    elseif event == fk.TargetSpecified and not isYang then
      return not player.room:getPlayerById(data.to):isNude()
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local isYang = player:getSwitchSkillState(self.name, true) == fk.SwitchYang
    local aim = data ---@type AimStruct

    if isYang then
      local from = room:getPlayerById(aim.from)
      player:drawCards(1, self.name)
      from:drawCards(1, self.name)
      local x = from:getMark("@@juzhan-turn")
      if x == 0 then x = {} end
      table.insert(x, player.id)
      room:setPlayerMark(from, "@@juzhan-turn", x)
    else
      local to = room:getPlayerById(aim.to)
      local from = player
      local num = math.max(1, player.maxHp - player.hp)
      local c = room:askForCardsChosen(from, to, 1, num, "he", self.name)
      room:obtainCard(from, c, false)
      local x = from:getMark("@@juzhan-turn")
      if x == 0 then x = {} end
      table.insert(x, to.id)
      room:setPlayerMark(from, "@@juzhan-turn", x)
    end
  end,
}
local juzhan_prohibit = fk.CreateProhibitSkill{
  name = "#ofl__juzhan_prohibit",
  is_prohibited = function(self, from, to)
    local x = from:getMark("@@juzhan-turn")
    if x == 0 then return false end
    return table.contains(x, to.id)
  end,
}
juzhan:addRelatedSkill(juzhan_prohibit)
yanyan:addSkill(juzhan)
Fk:loadTranslationTable{
  ["ofl_heg__yanyan"] = "严颜",
  ["#ofl_heg__yanyan"] = "断头将军",
  ["illustrator:ofl_heg__yanyan"] = "Town",
  ["ofl__juzhan"] = "拒战",
  [":ofl__juzhan"] = "转换技，阳：当你成为其他角色使用【杀】的目标后，你可以与其各摸一张牌，然后其本回合不能再对你使用牌。"..
  "阴：当你使用【杀】指定一名角色为目标后，你可以获得其至多X张牌（X为你已损失体力值且至少为1），然后你本回合不能再对其使用牌。",
  ["@@juzhan-turn"] = "拒战",

  ["~ofl_heg__yanyan"] = "宁可断头死，安能屈膝降！",
  ["$ofl__juzhan1"] = "砍头便砍头，何为怒耶！",
  ["$ofl__juzhan2"] = "我州但有断头将军，无降将军也！",
}

local zhuran = General(extension, "ofl_heg__zhuran", "wu", 4)
local danshou = fk.CreateTriggerSkill{
  name= "ofl__danshou",
  anim_type = "drawcard",
  events = {fk.TurnStart, fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if event == fk.TurnStart then
      if player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryRound) == 0 then
        return table.find(player.room.alive_players, function(p)
          return H.getKingdom(p) ~= "unknown"
        end)
      end
    else
      if player:hasSkill(self) and player:getMark("@ofl__danshou_enable-turn") > 0 and 
       target.phase > Player.Start and target.phase < Player.Finish then
        return #player:getCardIds(Player.Hand) <= player:getMark("@ofl__danshou_enable-turn")
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.TurnStart then
      return player.room:askForSkillInvoke(player, self.name, nil, "#ofl__danshou-ask:"..target.id)
    else
      if player.room:askForSkillInvoke(player, self.name, nil, "#ofl__danshou-choose:::"..player:getMark("@ofl__danshou_record-turn")) then
        self.cost_data = 1
      else
        self.cost_data = 2
      end
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TurnStart then
      room:setPlayerMark(player, "@ofl__danshou_record-turn", 1)
      local cids = player:getCardIds("hej") or {}
      player:throwAllCards("hej")
      room:setPlayerMark(player, "@ofl__danshou_enable-turn", #cids)
    else
      if self.cost_data == 1 then
        player:drawCards(player:getMark("@ofl__danshou_record-turn"), self.name)
        if not player.dead and room.current and not (room.current or {}).dead and player:getMark("@ofl__danshou_record-turn") >= 4 then
          if player.room:askForSkillInvoke(player, self.name, nil, "#ofl__danshou-damage:"..room.current.id) then
            room:doIndicate(player.id, { room.current.id })
            room:damage {
              from = player, 
              to = room.current,
              damage = 1, 
              skillName = self.name, 
              damageType = fk.NormalDamage,
            }
          end
        end
      else
        room:addPlayerMark(player, "@ofl__danshou_record-turn", 1)
      end
    end
  end,
}
zhuran:addSkill(danshou)
Fk:loadTranslationTable{
  ["ofl_heg__zhuran"] = "朱然",
  ["#ofl_heg__zhuran"] = "不动之督",
  ["illustrator:ofl_heg__zhuran"] = "F源",
  ["ofl__danshou"] = "胆守",
  [":ofl__danshou"] = "每轮限一次，一名角色回合开始时，若场上存在确定势力的角色，你可以弃置你区域内的所有牌，然后你于本回合每个阶段（准备阶段和结束阶段除外）开始时："..
  "若你的手牌数不大于X（X为你此次弃置的牌数），你摸一张牌或令你本回合“胆守”的摸牌数+1；当你一次性因“胆守”摸至少4张牌后，你可以对当前回合角色造成1点伤害。",
  ["@ofl__danshou_enable-turn"] = "胆守弃置",
  ["@ofl__danshou_record-turn"] = "胆守摸牌",
  ["#ofl__danshou-ask"] = "你可以于 %src 回合发动“胆守”",
  ["#ofl__danshou-choose"] = "胆守：你可以摸 %arg 张牌，或点击取消令你本回合“胆守”的摸牌数+1",
  ["#ofl__danshou-damage"] = "胆守：你可以对 %src 造成1点伤害",

  ["$ofl__danshou1"] = "胆识过人而劲勇，则见敌无所畏惧！",
  ["$ofl__danshou2"] = "胆守有余，可堪大任！",
  ["~ofl_heg__zhuran"] = "义封一生……不负国家！",
}

local zhujun = General(extension, "ofl_heg__zhujun", "qun", 4)
local gongjian = fk.CreateTriggerSkill{
  name = "ofl__gongjian",
  anim_type = "control",
  events = {fk.AfterCardsMove, fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return end
    if event == fk.AfterCardsMove then
      for _, move in ipairs(data) do 
        if move.moveReason == fk.ReasonDiscard and move.proposer == player.id and move.from ~= player.id then
          local cids = {}
          for _, info in ipairs(move.moveInfo) do
            if Fk:getCardById(info.cardId).trueName == "slash" then
              table.insertIfNeed(cids, info.cardId)
            end
          end
          if #cids > 0 then
            self.cost_data = cids
            player.room:delay(500)
            return true
          end
        end
      end
      return
    else
      if data.card and player:hasSkill(self) and player:getMark("ofl__gongjian_record") ~= 0 then
        if data.card.trueName == "slash" and player:getMark("ofl__gongjian_used-turn") == 0 then
          local room = player.room
          local targets = U.getActualUseTargets(room, data, event) or {}
          local records = player:getMark("ofl__gongjian_record")
          if #targets == 0 then return end
          for _, id in ipairs(targets) do
            table.removeOne(records, id)
          end
          if #records == 0 then
            return true
          end
        end
      end
    end
    return
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.AfterCardsMove then
      return true
    else
      return player.room:askForSkillInvoke(player, self.name, nil, "#ofl__gongjian-ask")
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.AfterCardsMove then
      local cids = self.cost_data
      room:obtainCard(player, cids, true, fk.ReasonPrey)
    else
      local targets = U.getActualUseTargets(room, data, event)
      for _, id in ipairs(targets) do
        local p = room:getPlayerById(id)
        local cids = room:askForCard(p, 2, 2, true, self.name, false, ".", "#ofl__gongjian-discard")
        if #cids > 0 then
          room:throwCard(cids, self.name, p, player)
        end
      end
    end
  end,
  refresh_events = {fk.TargetConfirmed},
  can_refresh = function(self, event, target, player, data)
    if data.card and player:hasSkill(self, true, true) then
      return data.card.trueName == "slash" and #U.getActualUseTargets(player.room, data, event) > 0
    end
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "ofl__gongjian_record", U.getActualUseTargets(player.room, data, event))
  end,
}
local kuimang = fk.CreateTriggerSkill{
  name = "ofl__kuimang",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.Death},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and (data.damage or {}).from then
      local killer = data.damage.from
      return not H.compareKingdomWith(player, target) and H.compareKingdomWith(killer, player) and (H.compareKingdomWith(target, HM.getRealNext(target)) or H.compareKingdomWith(target, HM.getRealLast(target)))
    end
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(2, self.name)
  end,
}
zhujun:addSkill(gongjian)
zhujun:addSkill(kuimang)
Fk:loadTranslationTable{
  ["ofl_heg__zhujun"] = "朱儁",
  ["#ofl_heg__zhujun"] = "镇贼保国",
  ["ofl__gongjian"] = "攻坚",
  [":ofl__gongjian"] = "你弃置其他角色的牌或你令其他角色弃置牌进入弃牌堆时，你可以获得其中的【杀】。每回合限一次，一名角色使用【杀】指定目标后，若目标角色均与本局游戏使用"..
  "的上一张【杀】相同，你可令目标角色弃置两张牌。",
  ["#ofl__gongjian-ask"] = "溃蟒：你可以令此【杀】的目标弃置两张牌",
  ["ofl__kuimang"] = "溃蟒",
  [":ofl__kuimang"] = "锁定技，与你势力相同的角色杀死一名与你势力不同且处于队列的角色时，你摸两张牌。",

  ["$ofl__gongjian1"] = "全军彻围，待其出城迎敌，再攻敌自散矣！",
  ["$ofl__gongjian2"] = "佯解敌围，而后城外击之，此为易破之道！",
  ["$ofl__kuimang1"] = "今非秦项之际，如若受之，徒增逆意！",
  ["$ofl__kuimang2"] = "兵有形同而势异者，此次乞降断不可受！",
  ["~ofl_heg__zhujun"] = "郭汜小竖！气煞我也！嗯……",
}


local gaoshun = General(extension, "ofl_heg__gaoshun", "qun", 4)
local xunzhan = fk.CreateTriggerSkill{
  name = "ofl__xunzhan",
  anim_type = "offensive",
  events = {fk.GeneralRevealed},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self.name) and player ~= target then
      local card = Fk:cloneCard("slash")
      return target.phase == target.NotActive and not player:prohibitUse(card) and not player:isProhibited(target, card)
    end
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#ofl__xunzhan-ask:"..target.id)
  end,
  on_use =function(self, event, target, player, data)
    local room = player.room
    local card = Fk:cloneCard("slash")
    local use = {
      from = player.id,
      tos = {{target.id}},
      card = card,
      extraUse = true,
    }
    room:useCard(use)
  end,
}
local huanjia = fk.CreateTriggerSkill{
  name = "ofl__huanjia",
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  events = {fk.TargetSpecified, fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and data.card then
      if data.card.trueName == "slash" then
        local room = player.room
        if event == fk.TargetSpecified and  target == player then
          local to = room:getPlayerById(data.to)
          if not to.dead and U.isOnlyTarget(to, data, event) then
            if to:getEquipment(Card.SubtypeWeapon) and not player:getEquipment(Card.SubtypeWeapon) then
              local cid = to:getEquipment(Card.SubtypeWeapon)
              if not cid then return end
              if U.canMoveCardIntoEquip(player, cid) then
                self.cost_data = cid
                return true
              end
              dbg()
            end
          end
        elseif event == fk.TargetConfirmed and target == player then
          local from = room:getPlayerById(data.from)
          if from:getEquipment(Card.SubtypeArmor) and not player:getEquipment(Card.SubtypeArmor) then
            local cid = from:getEquipment(Card.SubtypeArmor)
            if not cid then return end
            if U.canMoveCardIntoEquip(player, cid) then
              self.cost_data = cid
              return true
            end
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local cid = self.cost_data
    local room = player.room
    local card = Fk:getCardById(cid)
    if event == fk.TargetSpecified then
      local to = room:getPlayerById(data.to)
      if not data.extra_data then
        data.extra_data = {}
      end
      data.extra_data.huanjia_mark = {
        from = to.id,
        cid = cid,
      }
      U.moveCardIntoEquip(room, player, cid, self.name, true, player.name)
    else
      local from = room:getPlayerById(data.from)
      if not data.extra_data then
        data.extra_data = {}
      end
      data.extra_data.huanjia_mark = {
        from = from.id,
        cid = cid,
      }
      U.moveCardIntoEquip(room, player, cid, self.name, true, player.name)
    end
  end,
  refresh_events = {fk.CardUseFinished},
  can_refresh = function(self, event, target, player, data)
    if (data.extra_data or {}).huanjia_mark and player:hasSkill(self) then
      local room = player.room
      local from = room:getPlayerById(data.extra_data.huanjia_mark.from)
      local cid = data.extra_data.huanjia_mark.cid
      return not from.dead and room:getCardArea(cid) == Card.PlayerEquip
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local from = room:getPlayerById(data.extra_data.huanjia_mark.from)
    local cid = data.extra_data.huanjia_mark.cid
    room:obtainCard(from, cid, true)
  end,

} 
gaoshun:addSkill(xunzhan)
gaoshun:addSkill(huanjia)
Fk:loadTranslationTable{
  ["ofl_heg__gaoshun"] = "高顺",
  ["#ofl_heg__gaoshun"] = "炽战沙场",
  ["illustrator:ofl_heg__gaoshun"] = "鄧sir",
  ["ofl__xunzhan"] = "迅斩",
  [":ofl__xunzhan"] = "一名角色于其回合外明置武将时，你可以视为对其使用一张无距离限制的【杀】。",
  ["#ofl__xunzhan-ask"] = "迅斩：你可以视为对 %src 使用一张无距离限制的【杀】。",
  ["ofl__huanjia"] = "擐甲",
  [":ofl__huanjia"] = "锁定技，当你成为【杀】的目标后，若使用者装备区内有防具而你没有，你将此防具置入你的装备区，此【杀】结算完成后，其获得之；"..
  "当你使用【杀】指定唯一目标后，若目标角色装备区内有武器而你没有，你将此武器置入你的装备区，此【杀】结算完成后，其获得之。",
  ["$ofl__xunzhan1"] = "精练整齐，每战必克！",
  ["$ofl__xunzhan2"] = "陷阵杀敌，好不爽快！",
  ["$ofl__huanjia1"] = "好酒之徒，难堪大任，不入我营！",
  ["$ofl__huanjia2"] = "饮酒误事，必当严禁！",
  ["~ofl_heg__gaoshun"] = "力尽于布，与之偕死。",
}
]]


return extension